#include "Control_ScrollBar.h"

//#include "MouseStatus.h"

#include "Control_Menu.h"
#include "Host.h"

using namespace gui;

Control_ScrollBar::Control_ScrollBar(CallbackGetFloatValue NewCallbackGetValue, CallbackSetFloatValue NewCallbackSetValue, float NewMin, float NewMax, ColorRGBA<unsigned char> NewDisplayColor, std::string NewCaption, Vec<2, float> NewFontSize, ColorRGBA<unsigned char> NewForeColor, ColorRGBA<unsigned char> NewBackColor, Vec<2, float> NewPos, Vec<2, float> NewSize, Control_Menu* NewParentMenu, Host& NewParentHost) :
Control_StatusBar(NewCallbackGetValue, NewMin, NewMax, NewDisplayColor, NewCaption, NewFontSize, NewForeColor, NewBackColor, NewPos, NewSize, NewParentMenu, NewParentHost),
CallbackSetValue(NewCallbackSetValue)
{
}

Control_ScrollBar::~Control_ScrollBar()
{
}

void Control_ScrollBar::MouseDownLeft()
{
	float TmpF = 0;

	TmpF = ((ParentHost.Status.MousePos.X - (ParentMenuPos->X + Pos.X)) / Size.X);
	TmpF = Min + (TmpF * Range);
	Value = TmpF;
	RefreshCaption();

	CallbackSetValue(Value);
}

void Control_ScrollBar::MouseMove()
{
	if (ParentHost.Status.MouseIsLeftButtonPressed)
	{
		float TmpF = 0;

		TmpF = ((ParentHost.Status.MousePos.X - (ParentMenuPos->X + Pos.X)) / Size.X);
		TmpF = Min + (TmpF * Range);
		Value = TmpF;
		RefreshCaption();

		CallbackSetValue(Value);
	}
}